package com.bsj.power.pls.web;

import cn.dev33.satoken.annotation.SaIgnore;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.path.PathBanDTO;
import com.bsj.power.common.def.dto.path.PathDTO;
import com.bsj.power.common.def.dto.path.PathSearchDTO;
import com.bsj.power.common.def.vo.DeviceVO;
import com.bsj.power.common.def.vo.pls.PathVO;
import com.bsj.power.pls.service.PathService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description PathinfoController
 * @time 2024/4/20 10:41
 */
@Slf4j
@RestController
@RequestMapping("/path")
//@SaCheckPermission("/pls/path")
public class PathController {

    @Autowired
    private PathService pathService;

    /**
     * 添加围栏
     *
     * @param pathDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/20 11:58
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody PathDTO pathDTO) {
        return pathService.addPath(pathDTO);
    }

    /**
     * 删除围栏
     *
     * @param pathId
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/20 11:58
     */
    @PostMapping("/delete/{pathId}")
    public JsonResult delete(@PathVariable("pathId") Integer pathId) {
        return pathService.deletePath(pathId);
    }

    /**
     * 修改围栏
     *
     * @param pathDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/20 11:58
     */
    @PostMapping("/update")
    public JsonResult update(@RequestBody @Validated PathDTO pathDTO) {
        return pathService.updatePath(pathDTO);
    }

    /**
     * 获取单个围栏
     *
     * @param pathId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.pls.PathVO>
     * @author ljx
     * @time 2024/4/20 11:59
     */
    @GetMapping("/getById/{pathId}")
    public JsonResult<PathVO> getById(@PathVariable("pathId") Integer pathId) {
        return JsonResult.success(pathService.getPathById(pathId));
    }

    /**
     * 围栏分页
     *
     * @param pathSearchDTO
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.pls.PathVO>>
     * @author ljx
     * @time 2024/4/20 11:59
     */
    @SaIgnore
    @GetMapping("/page")
    public JsonResult<List<PathVO>> page(@Validated PathSearchDTO pathSearchDTO) {
        return pathService.pagePath(pathSearchDTO);
    }

    /**
     * 根据围栏id查询视频设备信息
     *
     * @param pathId
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.DeviceVO>>
     * @author ljx
     * @time 2024/9/18 14:32
     */
    @GetMapping("/getVideoDevicesByPathId/{pathId}")
    public JsonResult<List<DeviceVO>> getVideoDevicesByPathId(@PathVariable("pathId") Integer pathId) {
        return JsonResult.success(pathService.getVideoDevicesByPathId(pathId));
    }

    /**
     * 是否禁用
     *
     * @param pathBanDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/12/28 12:06
     */
    @PostMapping("/isBan")
    public JsonResult isBan(@Validated @RequestBody PathBanDTO pathBanDTO) {
        return pathService.isBan(pathBanDTO);
    }

}
